const ellipsis = true

const columnId = {
    title: 'id',
    dataIndex: 'id',
    type: 1,
    ellipsis
}
const columnUpdatedDate = {
    title: '更新时间',
    dataIndex: 'updatedDate',
    type: 1,
    ellipsis
}

const operate = {
    title: '操作',
    dataIndex: 'operation',
    width: 110
}

function init({ tableConfig = {} } = {}) {
    let columns = []
    if (tableConfig.id && tableConfig.id.hidden === false) {
        columns = [ columnId ]
    }
    columns = [ ...columns,
        ...Object.entries(tableConfig).filter(item => !item[1].hidden && item[1].name)
            .map(item => {
                item = item[1]
                let column = { title: item.title, dataIndex: item.name, ellipsis, type: item.type }
                return column
            })
    ]
    columns.push(columnUpdatedDate)
    columns.push(operate)
    return columns
}

export default {
    init
}